from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-20 14:02:31.820966
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 20, Nov, 2022
Time: 14:02:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.9999
Nobs: 846.000 HQIC: -51.3110
Log likelihood: 11072.5 FPE: 4.28549e-23
AIC: -51.5042 Det(Omega_mle): 3.85541e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299200 0.050476 5.928 0.000
L1.Burgenland 0.109796 0.034694 3.165 0.002
L1.Kärnten -0.106151 0.018482 -5.743 0.000
L1.Niederösterreich 0.210493 0.072529 2.902 0.004
L1.Oberösterreich 0.100603 0.068995 1.458 0.145
L1.Salzburg 0.251775 0.036783 6.845 0.000
L1.Steiermark 0.037378 0.048237 0.775 0.438
L1.Tirol 0.107531 0.039102 2.750 0.006
L1.Vorarlberg -0.060338 0.033709 -1.790 0.073
L1.Wien 0.053926 0.061625 0.875 0.382
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068121 0.104102 0.654 0.513
L1.Burgenland -0.030242 0.071553 -0.423 0.673
L1.Kärnten 0.047688 0.038117 1.251 0.211
L1.Niederösterreich -0.173113 0.149583 -1.157 0.247
L1.Oberösterreich 0.378739 0.142295 2.662 0.008
L1.Salzburg 0.288770 0.075861 3.807 0.000
L1.Steiermark 0.108065 0.099485 1.086 0.277
L1.Tirol 0.316070 0.080644 3.919 0.000
L1.Vorarlberg 0.022528 0.069521 0.324 0.746
L1.Wien -0.020341 0.127095 -0.160 0.873
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197709 0.026135 7.565 0.000
L1.Burgenland 0.092538 0.017964 5.151 0.000
L1.Kärnten -0.008738 0.009569 -0.913 0.361
L1.Niederösterreich 0.268343 0.037553 7.146 0.000
L1.Oberösterreich 0.114763 0.035724 3.213 0.001
L1.Salzburg 0.052797 0.019045 2.772 0.006
L1.Steiermark 0.016796 0.024976 0.672 0.501
L1.Tirol 0.098579 0.020246 4.869 0.000
L1.Vorarlberg 0.055902 0.017453 3.203 0.001
L1.Wien 0.112324 0.031908 3.520 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104887 0.026793 3.915 0.000
L1.Burgenland 0.047184 0.018416 2.562 0.010
L1.Kärnten -0.017212 0.009810 -1.754 0.079
L1.Niederösterreich 0.197118 0.038499 5.120 0.000
L1.Oberösterreich 0.279820 0.036623 7.640 0.000
L1.Salzburg 0.120086 0.019525 6.150 0.000
L1.Steiermark 0.101468 0.025605 3.963 0.000
L1.Tirol 0.123462 0.020756 5.948 0.000
L1.Vorarlberg 0.069151 0.017893 3.865 0.000
L1.Wien -0.026711 0.032711 -0.817 0.414
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130257 0.048525 2.684 0.007
L1.Burgenland -0.049398 0.033353 -1.481 0.139
L1.Kärnten -0.039398 0.017768 -2.217 0.027
L1.Niederösterreich 0.167641 0.069726 2.404 0.016
L1.Oberösterreich 0.139555 0.066329 2.104 0.035
L1.Salzburg 0.285022 0.035361 8.060 0.000
L1.Steiermark 0.032425 0.046373 0.699 0.484
L1.Tirol 0.163077 0.037591 4.338 0.000
L1.Vorarlberg 0.103883 0.032406 3.206 0.001
L1.Wien 0.068603 0.059243 1.158 0.247
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.058734 0.038428 1.528 0.126
L1.Burgenland 0.042507 0.026413 1.609 0.108
L1.Kärnten 0.049733 0.014071 3.535 0.000
L1.Niederösterreich 0.227212 0.055217 4.115 0.000
L1.Oberösterreich 0.272465 0.052527 5.187 0.000
L1.Salzburg 0.058039 0.028003 2.073 0.038
L1.Steiermark -0.006807 0.036724 -0.185 0.853
L1.Tirol 0.156269 0.029769 5.249 0.000
L1.Vorarlberg 0.068214 0.025663 2.658 0.008
L1.Wien 0.074185 0.046916 1.581 0.114
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185118 0.046000 4.024 0.000
L1.Burgenland -0.004479 0.031617 -0.142 0.887
L1.Kärnten -0.060911 0.016843 -3.616 0.000
L1.Niederösterreich -0.086486 0.066097 -1.308 0.191
L1.Oberösterreich 0.191637 0.062877 3.048 0.002
L1.Salzburg 0.059642 0.033521 1.779 0.075
L1.Steiermark 0.225828 0.043960 5.137 0.000
L1.Tirol 0.495006 0.035635 13.891 0.000
L1.Vorarlberg 0.047603 0.030720 1.550 0.121
L1.Wien -0.050957 0.056160 -0.907 0.364
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158617 0.052398 3.027 0.002
L1.Burgenland -0.009180 0.036015 -0.255 0.799
L1.Kärnten 0.064672 0.019186 3.371 0.001
L1.Niederösterreich 0.202555 0.075290 2.690 0.007
L1.Oberösterreich -0.067504 0.071622 -0.943 0.346
L1.Salzburg 0.222808 0.038183 5.835 0.000
L1.Steiermark 0.113634 0.050074 2.269 0.023
L1.Tirol 0.084233 0.040591 2.075 0.038
L1.Vorarlberg 0.121851 0.034992 3.482 0.000
L1.Wien 0.110031 0.063971 1.720 0.085
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.356939 0.030894 11.554 0.000
L1.Burgenland 0.008799 0.021235 0.414 0.679
L1.Kärnten -0.024772 0.011312 -2.190 0.029
L1.Niederösterreich 0.228209 0.044392 5.141 0.000
L1.Oberösterreich 0.157554 0.042229 3.731 0.000
L1.Salzburg 0.053246 0.022513 2.365 0.018
L1.Steiermark -0.018237 0.029524 -0.618 0.537
L1.Tirol 0.117675 0.023933 4.917 0.000
L1.Vorarlberg 0.071604 0.020632 3.471 0.001
L1.Wien 0.050276 0.037718 1.333 0.183
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043866 0.161153 0.192849 0.165644 0.131862 0.124475 0.070190 0.231053
Kärnten 0.043866 1.000000 0.001934 0.131622 0.045166 0.099335 0.427801 -0.050857 0.101886
Niederösterreich 0.161153 0.001934 1.000000 0.345622 0.166529 0.311109 0.127864 0.192062 0.341048
Oberösterreich 0.192849 0.131622 0.345622 1.000000 0.236013 0.340730 0.178083 0.180320 0.276182
Salzburg 0.165644 0.045166 0.166529 0.236013 1.000000 0.153255 0.145233 0.152903 0.140413
Steiermark 0.131862 0.099335 0.311109 0.340730 0.153255 1.000000 0.163238 0.148626 0.092431
Tirol 0.124475 0.427801 0.127864 0.178083 0.145233 0.163238 1.000000 0.122007 0.164390
Vorarlberg 0.070190 -0.050857 0.192062 0.180320 0.152903 0.148626 0.122007 1.000000 0.019650
Wien 0.231053 0.101886 0.341048 0.276182 0.140413 0.092431 0.164390 0.019650 1.000000